﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：DataAccessFundsOperatingType
// 文件功能描述：增减款类别数据访问层
//
// 
// 创建标识：2012-02-23 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DbAdapter.sqldbAdapter;
using System.Data.SqlClient;

namespace DAO.WaiGaoQiao
{
    public class DataAccessFundsOperatingType
    {
        /// <summary>
        /// 获取增减款类别信息
        /// </summary>
        /// <returns></returns>
        public DataSet SelFundsOperatingTypeInfo(int pagesize, int startindex, string strquery)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                string query = "select * from (select ROW_NUMBER() OVER(ORDER BY DepositTypeID ASC) rownumber,* " +
                               "from Con_DepositType_View) B "
                             + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString() + strquery;
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        /// <summary>
        /// 增减款类别数量
        /// </summary>
        /// <returns></returns>
        public int GetFundsOperatingTypeCount()
        {
            sqldb db = new sqldb();
            string query = "select count(1) from Con_DepositType_View";
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }

        /// <summary>
        /// 删除增减款类别
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public int DeleteFundsOperatingType(string ID)
        {
            sqldb db = new sqldb();
            string query = "select COUNT(*) from Con_DepositType where Account=2 and DepositTypeID=" + ID;
            object obj = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            if (Convert.ToInt32(obj) > 0)
            {
                return -2;
            }
            query = "Delete from Con_DepositType where DepositTypeID = '" + ID + "'";
            int rowcount = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
            return rowcount;
        }
        /// <summary>
        /// 检查是否为系统保留项
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public int SelFundsOperatingTypeEdit(string ID)
        {
            sqldb db = new sqldb();
            string query = "select COUNT(*) from Con_DepositType where Account=2 and DepositTypeID=" + ID;
            object obj = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(obj);
        }

        /// <summary>
        /// 保存增减款类别(新增界面下)
        /// </summary>
        /// <param name="supp"></param>
        /// <returns></returns>
        public int SaveFundsOperatingType(object[] obj)
        {
            sqldb db = new sqldb();
            string query = "insert into Con_DepositType(DepositTypeID,DepositName,Account,bUse,bShow) Values('" +
                obj[0] + "','" + obj[1] + "','" + obj[2] + "','" + obj[3] + "','" + obj[4] + "')";
            int rowcount = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
            return rowcount;
        }

        /// <summary>
        /// 根据编号获取一条增减款类别信息
        /// </summary>
        /// <param name="supplierNo"></param>
        /// <returns></returns>
        public DataSet GetFundsOperatingTypeInfoOne(string ID)
        {
            sqldb db = new sqldb();
            string query = "select * from Con_DepositType where DepositTypeID = '" + ID + "'";
            return db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
        }

        /// <summary>
        /// 保存增减款类别(修改界面下)
        /// </summary>
        /// <param name="supp"></param>
        /// <returns></returns>
        public int SaveFundsOperatingTypeEdit(object[] obj)
        {
            sqldb db = new sqldb();
            string query = "update Con_DepositType set DepositName='" + obj[1] + "',Account='" + obj[2] + "',bUse='" +
                obj[3] + "',bShow='" + obj[4] + "' where DepositTypeID=" + obj[0];
            int rowcount = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
            return rowcount;
        }

        public int CheckFundsOperatingType(int DepositTypeID)
        {
            sqldb db = new sqldb();
            string query = "select COUNT(*) from Con_DepositType where DepositTypeID=" + DepositTypeID;
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }
    }
}
